module.exports = (req, res, next) => {
  const body = req.body;
  const method = req.method;
  const path = req.path;
  const headers = req.headers;
  //authorization
  if (method == "POST" && path == "/login") {
    // if (body.name == "张三" && body.pass == "123") {
    if (body.name && body.pass == "123") {
      return res.status(200).json({
        user: {
          token: "Macro-2sxgs=+34",
          name: body.name,
        },
      });
    } else {
      return res.status(400).json({
        message: "用户名或则密码错误",
      });
    }
  }

  let notAuthUrl = ["/login", "/register"];
  if (!notAuthUrl.includes(path) && !headers.authorization) {
    return res.status(401).json({
      message: "token失效",
    });
  }
  next();
};
